// math_operations.cpp - 模块实现文件
module math_operations;

#include <iostream>
#include <stdexcept>

// 实现导出的函数
namespace MathOps {
    int add(int a, int b) {
        internal_log("执行加法运算");
        return a + b;
    }
    
    int subtract(int a, int b) {
        internal_log("执行减法运算");
        return a - b;
    }
    
    int multiply(int a, int b) {
        internal_log("执行乘法运算");
        return a * b;
    }
    
    double divide(double a, double b) {
        if (b == 0.0) {
            throw std::invalid_argument("除数不能为零");
        }
        internal_log("执行除法运算");
        return a / b;
    }
    
    // Calculator 类的实现
    Calculator::Calculator(const std::string& calc_name) : name(calc_name) {
        std::cout << "创建计算器: " << name << std::endl;
    }
    
    int Calculator::add(int a, int b) {
        int result = a + b;
        print_result("加法", result);
        return result;
    }
    
    int Calculator::subtract(int a, int b) {
        int result = a - b;
        print_result("减法", result);
        return result;
    }
    
    void Calculator::print_result(const std::string& operation, int result) {
        std::cout << name << " - " << operation << " 结果: " << result << std::endl;
    }
    
    std::string Calculator::get_name() const {
        return name;
    }
}

// 内部函数实现（模块私有）
namespace {
    void internal_log(const std::string& message) {
        std::cout << "[内部日志] " << message << std::endl;
    }
}
